using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Framework.Library.Utilities;
using Framework.Module.CMS.Library;
using Framework.Library.Components.Portal;
using Framework.Library;

namespace Framework.Module.CMS.Web.HomePage
{
    /// <summary>
    /// <!--copyright by tuannq (YM: si_da_ghe_lo)-->
    /// </summary>
    public partial class NavPortal : CMSWebControl
    {
        public DataTable dt = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.CurrentUser == null)
            {
                //dt = PortalController.GetPortalsByLang(AppEnv.GetLanguage(), 0, 1);
                //level = 0: chua dang nhap da hien ra roi`.
                //position = 1: hien tren menu trai.
                //nguyen edit to show portal parent
                dt = PortalController.GetPortalsByLangLeft(AppEnv.GetLanguage(), 0, 1);
                DataListMenu.DataSource = dt;
                DataListMenu.DataBind();
                
                
                
            }
            else
            {
                dt = PortalController.GetPortalsByLangLeft(AppEnv.GetLanguage(), 1, 1);
                // level = 0: chua dang nhap da hien ra roi`.
                // position = 1: hien tren menu trai.
                DataListMenu.DataSource = dt;
                DataListMenu.DataBind();
                //reaplate 

            }
        }
        protected void Item_DatalistBound(object sender,  DataListItemEventArgs e)
        {
            DataTable dtReturnPortal;
            
            if (!IsPostBack)
            {

                
                DataRowView currow = (DataRowView)e.Item.DataItem;
                DataList subportal = (DataList)e.Item.FindControl("DataListMenuSub"); 
                dtReturnPortal = PortalController.GetPortalsByLangParent(AppEnv.GetLanguage(),ConvertUtility.ToInt32(currow["PortalID"]));
                if (dtReturnPortal.Rows.Count > 0)
                {
                    subportal.DataSource = dtReturnPortal;
                    subportal.DataBind();
                }
                else
                {
                    Label bllURL = (Label)e.Item.FindControl("lbllayout");
                    bllURL.Text = "<a href=\"" + BuildUrlbyPortal(Framework.Library.Utilities.ConvertUtility.ToInt32(currow["PortalID"])) + "\"class=\"text2\">" + bllURL.Text +"</a>";
                }
                
            }
        }
        protected string getURLparent(int getID)
        {
            string sURL = "#";
            DataTable dtReturnPortal;
            dtReturnPortal = PortalController.GetPortalsByLangParent(AppEnv.GetLanguage(), ConvertUtility.ToInt32(getID));
            if (dtReturnPortal.Rows.Count > 0)
            {
                
            }
            else
            {
                sURL = BuildUrlbyPortal(Framework.Library.Utilities.ConvertUtility.ToInt32(getID));
            }
            return sURL;
        }
    }
}